let app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    animationData: {},
    showShopPopup: false,
    goGao: [],
    audit: false,
    wxuser: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.info("------")
    console.info(this.data.wxuser)
    wx.showLoading({
      title: '正在加载',
    })
    const that = this;
          wx.login({
            success: res => {
              const code = res.code
              console.info(code)
              wx.request({
                url: app.globalData.url + 'weixinController/login',
                data: {
                  code: code
                },
                success(ress) {
                  if (ress.data.status == 1) {

                    // if (ress && ress.header && ress.header['Set-Cookie']) {
                    //   
                      

                    // }
                    console.info(ress.header['Set-Cookie'] + "-====--============")
                    wx.setStorageSync('cookieKey', ress.header['Set-Cookie']); //保存Cookie到Storage
                    console.log(ress.data)
                    that.setData({
                      wxuser: ress.data
                    })
                    console.info(ress.data.data.manCardid + "-----")
                    if (ress.data.data.manCardid == "superman" || ress.data.data.companyNum == 1) {
                      that.setData({
                        audit: true
                      })
                    }
                    
                    wx.setStorageSync("user", ress.data)
                
                    wx.request({
                      url: app.globalData.url +'weixinController/weixingonggao',
                      data: {
                        usid: ress.data.manId
                      },
                      success: ress => {
                        console.info(ress.data)
                        that.setData({
                          goGao: ress.data
                        })
                        console.info(that.data.goGao)
                      }
                    })
                  } else if (ress.data.status == 2) {
                    wx.showModal({
                      title: '提示',
                      content: '未绑定账号，请手动登录',
                      success: function(res) {
                        wx.redirectTo({
                          url: '../login/login?usweiid=' + ress.data.usweiid,
                        })
                      }
                    })
                  }
                  wx.hideLoading();
                }
              })
            }
          })
          
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  clickMe() {
    this.showModal();
  },
  showModal() {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  hideModal: function () {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 200)
  },
  audit() {
    wx.navigateTo({
      url: '../audit/audit',
    })
  }, 
  athlete(){
    wx.navigateTo({
      url: '../athlete/athlete',
    })
  }, coach(){
    wx.navigateTo({
      url: '../coach/coach',
    })
  }, atsPlan(){
    wx.navigateTo({
      url: '../atsPlan/atsPlan',
    })
  },
  /**
   * 心得跳转
   */
  jumpXinDe:function(e){
    wx.showLoading({
      title: '加载中',
    })
    wx.navigateTo({
      url: '../atsAthleteGaineds/atsAthleteGaineds',
      success:()=>{
        wx.hideLoading()
      }
    })
  }
  ,
  zhiBiao: function () {
    const that = this;
    wx.showLoading({
      title: '加载中',
    })
    let user = wx.getStorageSync('user');

    
     if (user.data.companyNum == 4) {


          //console.log(e.currentTarget.dataset.text);
          wx.request({
            url: app.globalData.url +'AtsDataShowController/weixinselectAtsDataComparison',
            data: {
              athleteId: user.data.filId
              //athleteId:72
            },
            success: ress => {

              that.setData({
                objectArray: ress.data,
                zhuangtai: true
              })

              //console.info(that.data.objectArray)
              wx.hideLoading()
            }
          })

     } else  {

      wx.navigateTo({
        url: '../AtsDataShow/AtsDataShow',
        success: () => {
          wx.hideLoading()
        }
      })

    } 
    

  }
  ,
   /**
   * pick确认函数
   */
  sureCallBack_02(re) {
    const that=this;
    wx.showLoading({
      title: '加载中',
    })

    if (that.data.objectArray.length==0){
      wx.showToast({
        title: '没有数据了',
        icon: 'none',
        duration: 2000
      })
      that.setData({
        zhuangtai: false
      })

      return
    }
   


    wx.navigateTo({
      url: '../AtsDataBactihShow/AtsDataBactihShow?id=' + re.detail.choosedData[0].batchId,
      success: obj => {
        wx.hideLoading()
        that.setData({
          zhuangtai: false
        })
      }
    })

  },
  /**
   * pick取消函数
   */
  cancleCallBack_02() {
    this.setData({
      zhuangtai: false
    })
  },
  /**
   * 滚动公告点击函数
   */
  bin2: function (e) {
    wx.showLoading({
      title: '加载中',
    })
    console.info(this.data.goGao[e.currentTarget.dataset.text])
    wx.navigateTo({
      url: '../AtsAttachment/AtsAttachment?id=' + this.data.goGao[e.currentTarget.dataset.text].attachId,
      success: obj => {
        wx.hideLoading()
      }
    })
  }
})